package com.wwwzh.himalayafm.fragment.subfragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.wwwzh.himalayafm.R;
import com.wwwzh.himalayafm.fragment.SubFragment;

public class SubSubFragment extends Fragment {
    private Button subSubBtn;
    private Toolbar subSubTitle;
    private int TAG;

    public static SubSubFragment newInstance(int tag) {

        Bundle args = new Bundle();
        args.putInt("isShowTitle",tag);
        SubSubFragment fragment = new SubSubFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        TAG = getArguments().getInt("isShowTitle");

    }

    @Override
    public View onCreateView(LayoutInflater paramLayoutInflater, ViewGroup paramViewGroup, Bundle paramBundle) {
      View   rootView = paramLayoutInflater.inflate(R.layout.fragment_sub_sub, paramViewGroup, false);
        this.subSubBtn = ((Button) rootView.findViewById(R.id.SubSub_Btn));

        if (TAG == 1){
            subSubTitle = (Toolbar) rootView.findViewById(R.id.SubSubTitle_TL);
            setSubTitleShow();
        }

     final SubFragment   subFragment = (SubFragment) getParentFragment();
        this.subSubBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                subFragment.getSubViewPager().setCurrentItem(0);
            }
        });
        return rootView;
    }


    public void setSubTitleShow(){
        subSubTitle.setVisibility(View.VISIBLE);
        AppCompatActivity appCompatActivity = (AppCompatActivity) getActivity();
        appCompatActivity.setSupportActionBar(subSubTitle);
        ActionBar actionBar = appCompatActivity.getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setTitle("");

    }
}

